import React from 'react'
import { HashRouter, Route, Switch, Redirect } from 'react-router-dom'
import Lodin from '../pages/login/Login'
import SandBox from '../pages/sandbox/SandBox'
import News from '../pages/News/News.jsx'
import Detail from '../pages/News/Detail.jsx'

export default function Router() {
  return (
    <HashRouter>
      <Switch>
        <Route path='/login' component={Lodin} />
        <Route path='/news' component={News} />
        <Route path='/detail/:id' component={Detail} />
        <Route path='/' render={() => {
          return localStorage.getItem('token') ? <SandBox></SandBox> : <Redirect to='/login' />
        }}/>
      </Switch>
    </HashRouter>
  )
}
